<template>
	<el-col :span="componentModel.col*6" v-show="visible">
		<el-row>
			<el-col :span="8" class="field-label-div" v-if="!componentModel.noLabel">
				<label class="field-label">{{componentModel.label}}</label>
			</el-col>
			<el-col :span="componentModel.fieldcol">
				<el-date-picker type="date" placeholder="选择日期" v-model="vue_model" @change="onChangeHandler"  :readonly="readonly" size="mini"></el-date-picker>
			</el-col>
		</el-row>
	</el-col>
	
</template>

<script>
	import {sendComponentValueChangeRequest} from '@/utils/requestUtils.js';
	import utils from '@/utils/utils.js';
	export default {
		name:"DateComponent",
		props:["componentModel","scope"],
		data() {
			return {
				vue_model:"",
				visible:true,
				readonly:false,
				label: "",
			}
		},inject:['children'],
		mounted() {
			this.children.push(this);
		},beforeUnmount() {
			utils.removeArrayElement(this.children,this);
		},methods:{
			getValue(){
				if(this.vue_model==null||this.vue_model==""){
					return "";
				}else{
					var sMonth=this.vue_model.getMonth()+1+"";
					if(this.vue_model.getMonth()+1<10){
						sMonth="0"+(this.vue_model.getMonth()+1);
					}
					var sDate=this.vue_model.getDate()+"";
					if(this.vue_model.getDate()+1<10){
						sDate="0"+this.vue_model.getDate();
					}
					return this.vue_model.getFullYear()+"-"+sMonth+"-"+sDate;
				}
			},setProp(prop) {
				for(var k in prop){
					if(k=="value"){
						if(prop[k]==null){
							this.vue_model="";
						}else{
							var dateArray=prop[k].split("-");
							this.vue_model = new Date(parseInt(dateArray[0]),parseInt(dateArray[1])-1,parseInt(dateArray[2]));
						}
					}else if(k=="visible"){
						this.visible=prop[k];
					}else if(k=="readonly"){
						this.readonly=prop[k];
					}else if(k=="label"){
						this.label = prop[k];
					}
				}
			},
			onChangeHandler() {
				if (this.scope != undefined) {
					this.$emit("onValueChange", this);
					return;
				}
				sendComponentValueChangeRequest(this);
			}
		}
	}
</script>

<style>
</style>
